package com.koro.controller;

import com.koro.service.FlashSaleService;
import com.koro.vo.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "秒杀流程")
@RequestMapping("/seckill")
@RestController
public class FlashSaleController {

    /**
     * 1.预约
     *  预约成功，将用户id缓存到redis中
     * 2.把秒杀产品库存缓存到redis
     *  两个方式：1> 将库存数量缓存到redis中
     *          2> 将秒杀产品的id缓存到redis的list中，秒杀数量有多少，就往list存多少
     * 3.秒杀抢购
     *  校验商品库存，并且在下单成功后扣减库存
     */

    @Autowired
    private FlashSaleService flashSaleService;

    // 预约
    @ApiOperation(value = "预约",notes = "预约")
    @GetMapping("/prebook")
    public ResponseObject prebook(@RequestParam Integer id) {
        flashSaleService.prebook(id);
        return ResponseObject.ok();
    }

    // 缓存
    @ApiOperation(value = "缓存商品",notes = "缓存商品")
    @GetMapping("/cacheGoods")
    public ResponseObject cacheGoods(@RequestParam Integer id) {
        flashSaleService.cacheGoods(id);
        return ResponseObject.ok();
    }

    // 抢购
    @ApiOperation(value = "抢购",notes = "抢购")
    @GetMapping("/panicBuying")
    public ResponseObject panicBuying(@RequestParam Integer id) {
        flashSaleService.panicBuying(id);
        return ResponseObject.ok();
    }

}